<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/component/common.jsp" %>
<html>
<head>
    <title>医疗服务(钱湖)</title>
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap.min.css" type="text/css" type="text/css">
    <link rel="stylesheet" href="${frames}/css/lib/dataTables.bootstrap.css" type="text/css">
    <link rel="stylesheet" href="../assets/css/views/modules/_common.scss">
    <link rel="stylesheet" href="${newframe}/css/base/base.css" type="text/css">
    <link rel="stylesheet" href="${assets}/css/views/department/departmentMgr.css">
    <script src="${newframe}/js/compatible.js"></script>
    <script src="${js}/jquery-1.9.1.min.js"></script>
    <script src="../assets/js/views/vue.min.js"></script>
    <%@ include file="/WEB-INF/jsp/component/commonBottom.jsp" %>
    <style>
        #news,
        #card {
            width: 80px;
            height: 17px;
            font-size: 16px;
            font-weight: normal;
            font-stretch: normal;
            color: #666666;
        }

        #example_paginate {
            margin-top: 15px;
            width: 100%;
            text-align: center;
        }

        .form {
            margin-bottom: 0px !important;
        }

        .content {
            height: auto !important;
        }

        #example_paginate {
            padding-bottom: 30px;
        }

        .dataTables_empty {
            line-height: 30px;
        }

        .typePerson {
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
            overflow: hidden;
            width: 85%;
            margin: 0 auto;
        }
    </style>
</head>
<body>
<div class="wrap">
    <%@ include file="../../../breadline.jsp" %>
    <div class="content">
        <h1>医疗服务</h1>
        <div class="form">
            <label id="news" for="infoSearch">信息搜索:</label>
            <input id="infoSearch" type="text" class="SN" placeholder="病人姓名">
            <%--<input id="searchDoctor" type="text" placeholder="建档医生" class="SN">--%>
            <label id="card" for="IDNumber">身份证:</label>
            <input type="text" id="IDNumber" class="SN" placeholder="输入身份证号">
            <button class="search" id="query" onclick="refreshTable();">搜索</button>

            <%--<button id="import" onclick="importExcel()" class="addImg btn btn-info"
                    style="line-height:17px;margin-left:1%;font-size:17px;">
                导入
                <span id="linePhoto"></span>
            </button>--%>
            <input type="file" name="file" id="file" ref="file" style="display:none !important;">

        </div>
        <div id="tablepart" style="margin-left:19px;">
            <table id="example" class="display" cellspacing="10" width="100%">
                <thead>
                <tr style="background:#e6e6e6;">
                    <th>姓名</th>
                    <th>性别</th>
                    <th>id</th>
                    <th>出生日期</th>
                    <th>身份证</th>
                    <th>人群</th>
                    <th>建档医生</th>
                    <th>建档机构</th>
                    <th>建档时间</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
    <div class="loading" style="display: none;">
        <img src="${newframe }/images/slidebar/loading.gif" class="loadingImg">
    </div>
</div>
<script>
    var url = '${URL_PPPATIENTBASE_LIST_BY_SEARCH}';
    var diseasesType = 4;
    var href = window.location.search;
    var isStorage = false;
    // 判断当前页面是否从面包线跳转过来
    if (href.indexOf("isStorage") != -1) {
        isStorage = true
    }
    var number = 0;

    function initTable() {
        table = $('#example').DataTable({
            "dom": "<'row'<'col-xs-2'l><'#mytool.col-xs-10'><'col-xs-6'f>r>" +
                "t" +
                "<'row'<''i><''p>>",
            "bFilter": false,//去掉搜索框
            "bAutoWidth": true, //自适应宽度
            "info": false,
            "bSort": false,
            "sPaginationType": "full_numbers",
            "ordering": false,//是否允许Datatables开启排序
            "bProcessing": true,
            "bServerSide": true,
            "searching": false, //去掉搜索框方法一
            'lengthChange': false,
            "oPaginate": false,
            "sAjaxSource": url,
            "iDisplayStart": number,
            "sAjaxDataProp": "dataList",//查询后，返回的集合
            "fnServerData": function (sSource, aoData, fnCallback) {  //查询条件
                aoData.push(
                    {
                        "name": "realname",
                        "value": $("#infoSearch").val()
                    },

                    {
                        "name": "idcard",
                        "value": $("#IDNumber").val()
                    },
                    {
                        "name": "diseasesType",
                        "value": diseasesType
                    }
                ),
                    $.ajax({
                        "dataType": 'json',
                        "url": sSource,
                        "type": 'post',
                        "data": aoData,
                        "success": function (resp) {
                            console.log(resp)
                            fnCallback(resp)
                        }
                    });
            },
            "aoColumns": [{
                "targets": 0,
                "data": null,
                "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                    $(nTd).html('' +
                        '&nbsp;&nbsp;<a href="#" onClick="Then(this)" style="color:black;border-bottom:#35acfd dashed 1px">' + oData.realname + '</a>' +
                        '');
                }
            }, {
                "targets": 1,
                "data": null,
                "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                    if (oData.gender === 1) {
                        $(nTd).text("男")
                    } else if (oData.gender === 2) {
                        $(nTd).text("女")
                    } else {
                        $(nTd).text("")
                    }
                }
            }, {
                "mDataProp": "id", "visible": false
            }, {
                "targets": 3,
                "data": null,
                "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                    if (oData.idcard.length === 18) {
                        oData.birthday = oData.idcard.slice(6, 14).slice(0, 4) + '-' + oData.idcard.slice(6, 14).slice(4, 6) + '-' + oData.idcard.slice(6, 14).slice(6, 8)
                    } else {
                        oData.birthday = ""
                    }
                    $(nTd).text(oData.birthday)
                }
            }, {
                "targets": 4,
                "data": null,
                "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                    $(nTd).html("<a href='javascript:void(0)' data-id=" + oData.idcard + " onclick='Go(this)' class='searchBtn'>" + oData.idcard.slice(0,6) + '********' + oData.idcard.slice(14,18) + "</a>");
                }
            }, {
                "targets": 5,
                "data": null,
                "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                    $(nTd).html('<p class="typePerson"' + 'title=' + Type(oData.diseasesType) + '>' + Type(oData.diseasesType) + '</p>')
                }
            }, {
                "targets": 6,
                "data": null,
                "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                    $(nTd).html('<p class="typePerson"' + 'title=' + isNull(oData.doctor) + '>' + isNull(oData.doctor) + '</p>')
                }
            }, {
                "targets": 7,
                "data": null,
                "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                    $(nTd).html('<p class="typePerson"' + 'title=' + isNull(oData.hospName) + '>' + isNull(oData.hospName) + '</p>')
                }
            }, {
                "targets": 8,
                "data": null,
                "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                    $(nTd).text(oData.createdtime.slice(0, 10))
                }
            }],
            "createdRow": function (row, data, index) {

            },
            "oLanguage": {//插件的汉化
                "sLengthMenu": "32",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "oPaginate": {
                    "sFirst": "",
                    "sPrevious": "<b>上一页<b>",
                    "sLast": "",
                    "sNext": "<i>下一页</i>"

                },
                "sZeroRecords": "没有检索到数据",
                "sProcessing": "<img src='' />",
                "sSearch": "搜索"
            }

        });
    }

    $(document).ready(function () {
        if (isStorage) {
            number = (Number(sessionStorage.getItem('pageNumber')) - 1) * 10;
        }
        initTable();
    });

    function importExcel() {
        $('#file').click();
    }

    $(function () {

        $("#file").change(function () {
            // 创建 blob 对象，浏览器将文件放入内存中，并生成标识
            var img_src = URL.createObjectURL($(this)[0].files[0]);
            let teacherImg = $(this).val();
            let teacherImgfile = getFileType(teacherImg);
            if (teacherImgfile != "xls" && teacherImgfile != "xlsx") {
                alert('请选择Excel文件！');
                $("#file").val("");
                return;
            }
            // 给img标检的src赋值
            // document.getElementById("linePhoto").src=img_src;
            var formData = new FormData();
            formData.append('file', $("#file")[0].files[0]);
            // 提交
            $.ajax({
                url: '${URL_ACCOMPANY_BLDATA_EXCEL_IMPORT}',
                processData: false,
                contentType: false,
                data: formData,
                type: 'post',
                dataType: 'json',
                success: function (res) {
                    alert(res.msg);
                }
            })
        });
    });

    function getFileType(filePath) {
        var startIndex = filePath.lastIndexOf(".");
        if (startIndex != -1)
            return filePath.substring(startIndex + 1, filePath.length).toLowerCase();
        else return "";
    }

    function isNull(data) {
        var str = '';
        if (data != null) {
            str = data
        }
        return str
    }

    function Go(obj) {
        var rowIndex = $(obj).parents("tr").index();
        var id = $('#example').DataTable().row(rowIndex).data().id;//此处拿到隐藏列的id
        var name = $(obj).attr('data-id');
        // 判断
        var Type = obj.parentNode.parentNode.children[4].innerText
        var ids = typePerson(Type);
        console.log(ids)
        console.log(ids)
        $.ajax({
            url: "${URL_SCREENING_GETBREADLINE}",
            dataType: 'json',
            type: 'post',
            success: function (data) {
                breadLine = JSON.parse(data.data)
                var url = '${URL_BONELOOSE_QIANHU_BLACCOMPANYS}?idcard=' + name + '&id=' + id + '&diseasesType=' + diseasesType + '&type=' + ids
                breadLine.push({
                    name: '医疗服务',
                    href: url
                })
                $.ajax({
                    url: '${URL_SCREENING_SAVEBREADLINE}',
                    data: {
                        breadLine: JSON.stringify(breadLine)
                    },
                    dataType: 'json',
                    type: 'post',
                    success: function (data) {
                        parent.showSrc('${URL_BONELOOSE_QIANHU_BLACCOMPANYS}?idcard=' + name + '&id=' + id + '&diseasesType=' + diseasesType + '&type=' + ids)
                    }
                })
            }
        })
    }

    function Then(obj) {
        var idDom = obj.parentNode.parentNode.children[3].children[0];
        var idcard = $(idDom).attr('data-id');
        var rowIndex = $(obj).parents("tr").index();
        var id = $('#example').DataTable().row(rowIndex).data().id;//此处拿到隐藏列的id
        var Type = obj.parentNode.parentNode.children[4].innerText
        var ids = typePerson(Type);
        console.log(ids)
        $.ajax({
            url: "${URL_SCREENING_GETBREADLINE}",
            dataType: 'json',
            type: 'post',
            success: function (data) {
                breadLine = JSON.parse(data.data)
                var url = '${URL_BONELOOSE_QIANHU_BLACCOMPANYS}?idcard=' + idcard + '&id=' + id + '&diseasesType=' + diseasesType + '&type=' + ids
                breadLine.push({
                    name: '医疗服务信息',
                    href: url
                })
                $.ajax({
                    url: '${URL_SCREENING_SAVEBREADLINE}',
                    data: {
                        breadLine: JSON.stringify(breadLine)
                    },
                    dataType: 'json',
                    type: 'post',
                    success: function (data) {
                        parent.showSrc('${URL_BONELOOSE_QIANHU_BLACCOMPANYS}?idcard=' + idcard + '&id=' + id + '&diseasesType=' + diseasesType + '&type=' + ids)
                    }
                })
            }
        })
    }

    function getValue() {
        var oTable = $('#example').dataTable();
        var oSettings = oTable.fnSettings();
        // 获取页码值
        return oSettings._iDisplayStart;
    }

    window.onbeforeunload = function (e) {
        var e = window.event || e;
        var pageNumber = getValue()
        // 获取当前页码
        if (pageNumber == 0) {
            pageNumber = 1;
        } else {
            pageNumber = pageNumber / 10 + 1;
        }
        console.log(pageNumber)
        // 保存在本地
        sessionStorage.setItem('pageNumber', pageNumber);
    }
</script>
</body>
</html>
